<template>
    <div>
        <ul class="mui-table-view">
            <li class="mui-table-view-cell mui-media" v-for="item in newslist" :key="item.id">
                <router-link :to="'/home/newinfo/' + item.id">
                    <img class="mui-media-object mui-pull-left" :src="item.img_url" alt/>
                    <div class="mui-media-body">
                        {{ item.title }}
                        <p class="mui-ellipsis">
                            <span>发表时间:{{item.add_time | dateFormat('YYYY-MM-DD')}}</span>
                            <span>点击:{{item.click}}次</span>
                        </p>
                    </div>
                </router-link>
            </li>
        </ul>
    </div>
</template>

<script lang="ts">
  import {Component, Vue} from 'vue-property-decorator';

  interface NewsListInterface {
    id: number;
    title: string;
    add_time: Date;
    zhaiyao: string;
    click: number;
    img_url: string;
  }

  @Component
  export default class NewsList extends Vue {
    private newslist: NewsListInterface[] = [];

    private created(): void {
      this.getLunBo();
    }

    private async getLunBo() {
      const {data} = await this.$http.get('http://www.liulongbin.top:3005/api/getnewslist');
      if (data.status === 0) {
        this.newslist = data.message;
      }
    }
  }
</script>

<style scoped lang="scss">
    .mui-ellipsis {
        display: flex;
        justify-content: space-between;
    }
</style>
